//打开对话框
function openDialog(event){
    console.log(event);
    openUpdateDialog(event);
}

//打开修改窗口
function openUpdateDialog(event) {
    var modalId = "Modal1";
    //打开对话框
    h3ui.widgets[modalId].props.visible= true;
    //Object.keys(event.data.row).forEach(a=>{ h3ui.models.t_account.item[a]=event.data.row[a] })
    h3ui.models.t_account.item = event.data.row;
}

function toReload(event){
    var formListId = event.node.id.split("_")[1];
    reloadList(formListId);
}

//列表刷新事件
function reloadList(formListId) {
    var list = h3ui.widgets[formListId];
    if(formListId == "FormList8"){
        var pageIndex = h3ui.widgets.Pagination8.props.current;
        var filter = h3ui.widgets.ModelQueryForm8.props.value;
        list.emit('load', {
            pageIndex: pageIndex,
            pageSize: 10,
            filter
        });
    }else if(formListId == "FormList12"){
        var pageIndex = h3ui.widgets.Pagination12.props.current;
        var filter = h3ui.widgets.ModelQueryForm12.props.value;
        list.emit('load', {
            pageIndex: pageIndex,
            pageSize: 10,
            filter
        });
    }

}

function updateAccount(event){
    var param = h3ui.models.t_account.item;
    console.log(param);
    toCallService({
        "reloadListId":"FormList8",
        "serviceName":"updateAccount",
        "msg":"",
        "closeModalId":"Modal1",
        "param":param
    });
}


/**
 * 提交自定义业务服务
 * map:{formListId : "", // select列表id
 * 	reloadListId : "",// 重新加载的list
 * 	serviceName : "",// 服务名称
 * 	msg :"", // 提示内容
 * 	closeModalId:"", // 需要关闭的对话框id, 多个用","隔开
 * 	param : {} // 提交参数
 * }
 */
function toCallService(map){

    h3ui.$confirm({
        title: map.msg+'确认提交吗',
        onOk() {
            callService(map);
        }
    });
}

/** *
 * @param {serviceName,param,reloadListId,closeModalId} map
 *
 * serviceName 服务名称
 * param  服务参数
 * reloadListId 服务成功后指定刷新列表
 * closeModalId 服务成功后指定关闭对话框
 */
function callService(map) {
    h3ui.services[map.serviceName](map.param).then(res=>{
        if(res.success ){
            h3ui.$message.success('提交成功');

            if(map.reloadListId){
                reloadList(map.reloadListId);
            }

            if(map.closeModalId){
                map.closeModalId.split(",").forEach(a=>{
                    if(a) h3ui.widgets.a.props.visible= false;
                })
            }
        } else {
            h3ui.$message.error(res.errMessage ||  '提交失败');
        }
    })
}
